# from websocket import create_connection
# ws = create_connection("ws://echo.websocket.org/")
# print("Sending 'Hello, World'...")
# ws.send("Hello, World")
# print("Sent")
# print("Receiving...")
# result = ws.recv()
# print("Received " +result)
# ws.close()




from ws4py.client.threadedclient import WebSocketClient

class CG_Client(WebSocketClient):

  def opened(self):
    req = "Hello, World"
    self.send(req)

  def closed(self, code, reason=None):
    print("Closed down:", code, reason)

  def received_message(self, resp):
    result = str(resp)
    print(" 返回 "+result)

if __name__ == '__main__':
  ws = None
  try:
    ws = CG_Client('ws://echo.websocket.org')
    ws.connect()
    ws.run_forever()
  except KeyboardInterrupt:
    ws.close()